import { FileListType } from '@renderer/types/global'
import axios from 'axios'

// 模块：产品明细，报价单，销售订单
const modelUrl = '/produce'
// 产品明细
export interface ProductReq {
  productId?: string
  productName: string
  productCategory: string
  specModel: string
  unit: string
  materialName: string
  spec: string
  materialCode: string
  materialDesc: string
  fluteType: string
  crimpLine: string
  remark: string
  customerId: string
  productType: number
}
export interface ProductRes {
  currentPage?: number
  pageSize?: number
  totalPage?: number
  totalCount?: number
  list: ProductResItem[]
}
export interface ProductResItem {
  productId?: string
  productName?: string
  productCategory?: string
  specModel?: string
  unit?: string
  materialName?: string
  spec?: string
  materialCode?: string
  materialDesc?: string
  fluteType?: string
  crimpLine?: string
  remark?: string
  customerId?: string
  createdDt?: string
  customerName?: string
  index?: number // 导出的序号
}
export interface ProductSearch {
  productName?: string
  customerName?: string
  specModel?: string
  unit?: string
  productCategory?: string
  materialName?: string
  spec?: string
  materialCode?: string
  materialDesc?: string
  crimpLine?: string
  fluteType?: string
  remark?: string
  productId?: string
  customerId?: string
  tenantId?: string
  productType?: number
  orderBy?: number
}
export function editProduct(data: ProductReq) {
  return axios.post<ProductRes>(modelUrl + '/erpProductAdit', data)
}

export function delProduct(data: { productId: string }) {
  return axios.post<object>(modelUrl + '/erpProductDel', data)
}

export function getProductDetail(data: { productId: string }) {
  return axios.post<ProductRes>(modelUrl + '/erpProductDetail', data)
}

export function getProductAllList(data?: ProductSearch) {
  return axios.post<ProductRes>(modelUrl + '/erpProductList', data)
}

export function getProductPageList(data: ProductSearch) {
  return axios.post<ProductRes>(modelUrl + '/erpProductPage', data)
}

export function batchDelProduct(data: { idList: string[] }) {
  return axios.post<ProductRes>(modelUrl + '/erpProductDelBatch', data)
}

// 报价单
export interface QuotationReq {
  quotationOrderId?: string
  isInclTax?: number
  customerId: string
  deliveryMethod: string
  paymentMethod: string
  remark: string
  detailList: {
    productId: string
    specModel: string
    unitPrice: number
    unit: string
  }[]
}
export interface QuotationRes {
  currentPage?: number
  pageSize?: number
  totalPage?: number
  totalCount?: number
  list: QuotationResItem[]
}
export interface QuotationResItem {
  quotationOrderId: string
  quotationOrderCode: string
  customerId: string
  isInclTax: number
  deliveryMethod: string
  paymentMethod: string
  remark: string
  customerName: string
  customerAddress: string
  contactName: string
  contactPhone: string
  quotationOrderDetailId: string
  detailList: {
    quotationOrderDetailId: string
    quotationOrderId: string
    productId: string
    specModel: string
    unitPrice: number
    productName: string
    productCategory: string
    unit: string
    materialName: string
    spec: string
    materialCode: string
    materialDesc: string
    fluteType: string
    crimpLine: string
  }[]
  createdBy: string
  createdDt: string
  updatedBy: string
  updatedDt: string
  index?: number // 导出的序号
}
export interface QuotationSearch {
  quotationOrderCode?: string
  customerName?: string
  createdStartDate?: string
  createdEndDate?: string
  deliveryMethod?: string
  paymentMethod?: string
  remark?: string
  quotationOrderId?: number
  customerId?: number
  isInclTax?: number
  tenantId?: number
  createTime: string[]
  specModel?: string
  productName?: string
}
export function editQuotation(data: QuotationReq) {
  return axios.post<QuotationRes>(modelUrl + '/quotationOrderAdit', data)
}

export function delQuotation(data: { quotationOrderId: string }) {
  return axios.post<object>(modelUrl + '/quotationOrderDel', data)
}

export function getQuotationDetail(data: { quotationOrderId: string }) {
  return axios.post<QuotationResItem>(modelUrl + '/quotationOrderDetail', data)
}

export function getQuotationAllList(data: QuotationSearch) {
  return axios.post<QuotationRes>(modelUrl + '/quotationOrderList', data)
}

export function getQuotationPageList(data: QuotationSearch) {
  return axios.post<QuotationRes>(modelUrl + '/quotationOrderPage', data)
}

export function batchDelQuotation(data: { idList: string[] }) {
  return axios.post<QuotationRes>(modelUrl + '/quotationOrderDelBatch', data)
}
// 销售订单
export interface SaleReq {
  isInclTax: number
  customerId: string
  orderStatus: string
  orderAmt?: number
  sellersId: string
  planDeliveryDate: string
  deliveryMethod: string
  settlementType: string
  remark: string
  detailList: {
    productId?: string
    unitPrice?: number
    unit?: string
    specModel?: string
    qty?: number
    amt?: number
    status?: string
  }[]
  saleOrderId?: string
  saleOrderCode?: string
  fileList: FileListType[]
}
export interface SaleRes {
  currentPage?: number
  pageSize?: number
  totalPage?: number
  totalCount?: number
  list: SaleResItem[]
}

export interface SaleDetailList {
  qty?: number
  unitPrice?: number
  amt?: number
  saleOrderDetailId?: string
  saleOrderId?: string
  productId?: string
  productName?: string
  productCategory?: string
  specModel?: string
  unit?: string
  materialName?: string
  spec?: string
  materialCode?: string
  materialDesc?: string
  fluteType?: string
  crimpLine?: string
}
export interface SaleResItem {
  saleOrderId: string
  saleOrderCode: string
  customerId: string
  orderStatus: string
  sellersName: string
  planDeliveryDate: string
  deliveryMethod: string
  settlementType: string
  remark: string
  customerName: string
  customerAddress: string
  contactName: string
  contactPhone: string
  orderAmt: number
  isInclTax: number
  detailList: SaleDetailList[]
  sellersId: string
  fileList: FileListType[]
  createdBy: string
  createdDt: string
  updatedBy: string
  updatedDt: string
  index?: number // 导出的序号
}
export interface SaleResItemHandle {
  saleOrderId: string
  saleOrderCode: string
  customerId: string
  orderStatus: string
  sellersName: string
  sellersId: string
  planDeliveryDate: string
  deliveryMethod: string
  settlementType: string
  remark: string
  customerName: string
  customerAddress: string
  contactName: string
  contactPhone: string
  orderAmt: number
  files?: string[]
  isInclTax: number | string
  qty?: number
  unitPrice?: number
  amt?: number
  saleOrderDetailId?: string
  productId?: string
  productName?: string
  productCategory?: string
  specModel?: string
  unit?: string
  materialName?: string
  spec?: string
  span?: number
  materialCode?: string
  materialDesc?: string
  fluteType?: string
  crimpLine?: string
  createdBy: string
  createdDt: string
  updatedBy: string
  updatedDt: string
  index?: number // 导出的序号
  detailList: SaleDetailList[]
  fileList: FileListType[]
}
export interface SaleSearch {
  customerName?: string
  createdStartDate?: string
  createdEndDate?: string
  saleOrderCode?: string
  orderStatus?: string
  sellersName?: string
  planDeliveryStartDate?: string
  planDeliveryEndDate?: string
  planDeliveryDate?: string[]
  deliveryMethod?: string
  settlementType?: string
  remark?: string
  saleOrderId?: string
  customerId?: string
  orderAmt?: number
  isInclTax?: number
  tenantId?: string
  createTime?: string[]
  // 需要增加的字段
  // 计划交货日期是区间
  productName?: string
}
export function editSale(data: SaleReq) {
  return axios.post<SaleRes>(modelUrl + '/saleOrderAdit', data)
}

export function delSale(data: { saleOrderId: string }) {
  return axios.post<object>(modelUrl + '/saleOrderDel', data)
}

export function getSaleDetail(data: { saleOrderId: string }) {
  return axios.post<SaleResItem>(modelUrl + '/saleOrderDetail', data)
}

export function getSaleAllList(data: SaleSearch) {
  return axios.post<SaleRes>(modelUrl + '/saleOrderList', data)
}

export function getSalePageList(data: SaleSearch) {
  return axios.post<SaleRes>(modelUrl + '/saleOrderPage', data)
}

export function batchDelSale(data: { idList: string[] }) {
  return axios.post<QuotationRes>(modelUrl + '/saleOrderDelBatch', data)
}
